<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<meta id="viewport" name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1, user-scalable=no">
	<meta name="apple-itunes-app">
	<title>分享送会员</title>
	<script src="js/jquery-3.2.1.min.js"></script>
	<script src="js/flexible.js"></script>
	<script src="js/clipBoard.js"></script>
	<link rel="stylesheet" href="css/share_act20171019.css">
</head>
<body>
	<div class="share-act">
		<section>
			<img src="images/share_t1.jpg" alt="">
			<div class="btns">
				<img src="images/share_t2.jpg" alt="">
				<a href="javascript:void(0);" class="share-btn"><img id="btnText" src="images/btn_get.png" alt=""></a>
			</div>
			<img src="images/share_t3.jpg" alt="">
		</section>
		<section class="mt30">
			<img src="images/share_m1.jpg" alt="">
			<img src="images/share_m2.jpg" alt="">
		</section>
		<section class="mt30">
			<img src="images/share_b1.jpg" alt="">
			<img id="wx_id" src="images/share_b2.jpg" alt="">
			<img src="images/share_b3.jpg" alt="">
		</section>
	</div>
	<div class="share-notice">
		<img src="images/share_tips.png" alt="">
	</div>
	<script>
		// 判断是否分享过
		var userId = GetQueryString('userId'),
			bannerId = GetQueryString('bannerId'),
			data = {'userId': userId,'bannerId': bannerId},
			baseUrl = 'http://183.47.42.218:40021';
		$.ajax({
			url: baseUrl + '/productManage/ddb/share-h5/get-status',
			type: 'POST',
			dataType: 'json',
			contentType: 'application/json;charset=utf-8',
    		data: JSON.stringify(data),
			success: function(json){
				if(json.state == 1){
					$('#btnText').attr('src', 'images/btn_buy.png');
					$('#btnText').parents('a').addClass('buy-btn');
				}else{
					$('#btnText').attr('src', 'images/btn_get.png');
				}
			}	
		});

		// 我要分享
		$('.share-btn').click(function(e){
			if($(this).hasClass('buy-btn')){	
				// 点击购买
				alert('go buy');
			}else{
				$('.share-notice').fadeIn();
				setTimeout(function(){
					$('.share-notice').fadeOut();
				},2000);
			}
			e.stopPropagation();
		});

		// 复制微信公众号
		$('#wx_id').click(function(){
			var _this = (this);
			var test = new clipBoard(_this, {
	            copy: function() {
	                return 'jtyddb';
	            },
	            afterCopy: function() {
	            	tips('复制成功');
	    		}
	    	});
		});

		// tips 提示
		function tips(message){
			var tips = document.getElementsByClassName('tips'), 
				div = document.createElement('div');
			div.setAttribute('class', 'tips');
			div.innerHTML = message;
			while(tips.length > 0){		// 防止重复点击
		        return false;
		    }
			document.body.appendChild(div);
			setTimeout(function(){
				var elements = document.getElementsByClassName('tips');
				while(elements.length > 0){
				   elements[0].parentNode.removeChild(elements[0]);
				}
			}, 2000);
		}

		//获取地址栏的参数
		function GetQueryString(name) {
		    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
		    var r = window.location.search.substr(1).match(reg);
		    if (r != null) return unescape(r[2]); return null;
		}

	</script>
</body>
</html>